﻿using CPPEI.Coolzon.Event.Core;
using CPPEI.Coolzon.Event.NCL;
using CPPEI.Coolzon.Metadata;
using CPPEI.Coolzon.UI;
using CPPEI.Coolzon.UI.Event;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Coolvis.Console.Theme.MainViewControl
{
    /// <summary>
    /// SpeechComment.xaml 的交互逻辑
    /// </summary>
    public partial class SpeechComment : UserControl
    {
        /// <summary>
        /// 当前场景
        /// </summary>
        private Scene _CurrentScene;
        public SpeechComment()
        {
            InitializeComponent();
            SetTextDecorations();

            CPPEI.Coolzon.UI.Views.RenderView renderView = (CPPEI.Coolzon.UI.Views.RenderView)UIContext.Current.RenderView;

            _CurrentScene = renderView.CurrentScene;

            SetComments();

            CoreEventBus.Register(this);
        }

        /// <summary>
        /// 设置演讲备注内容
        /// </summary>
        private void SetComments()
        {
            if (_CurrentScene != null && _CurrentScene.CommentsLink != null)
            {
                string absFilePaht = SolutionResourceManager.GetAbsoluteFilePath(_CurrentScene.CommentsLink.Name);
                if (!File.Exists(absFilePaht))
                {
                    tbComments.Document.Blocks.Clear();
                    return;
                }
                using (StreamReader sr = new StreamReader(absFilePaht, Encoding.GetEncoding("gb2312")))
                {
                    TextRange textRangeAll = new TextRange(tbComments.Document.ContentStart, tbComments.Document.ContentEnd);
                    textRangeAll.Load(sr.BaseStream, DataFormats.Rtf);
                }
            }
            else
            {
                tbComments.Document.Blocks.Clear();
            }
        }

       

        /// <summary>
        /// 设置下划线样式
        /// </summary>
        public void SetTextDecorations()
        {
            TextDecoration textDecoration = new TextDecoration();
            Pen pen = new Pen();
            pen.Thickness = 3;
            DashStyle dashStyle = new DashStyle();
            dashStyle.Dashes.Add(1);
            dashStyle.Dashes.Add(2);
            pen.DashStyle = dashStyle;
            pen.Brush = new SolidColorBrush(Color.FromArgb(0xAA, 0xB7, 0xB7, 0xB7));
            textDecoration.Pen = pen;
            textDecoration.PenOffset = 10;
            textDecoration.PenOffsetUnit = TextDecorationUnit.Pixel;
            textDecoration.PenThicknessUnit = TextDecorationUnit.Pixel;
            richTextBoxRun.TextDecorations.Add(textDecoration);
        }
    }
}
